package com.arlin.spring.common;

import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;

/**
 * @ClassName: ObjectUtil
 * @Description: 对象工具类
 * @Author: arlin
 * @Date: 2021/12/12
 */
public class ObjectUtil {

    /**
     * 将String转换为目标类型
     *
     * @param targetType 目标类型
     * @param s          string
     * @throws NumberFormatException 当string到number时，如果string不是数字，则抛出NumberFormatException
     */
    public static Object convert(Class<?> targetType, String s) {
        PropertyEditor editor = PropertyEditorManager.findEditor(targetType);
        editor.setAsText(s);
        return editor.getValue();
    }
}
